from selenium.webdriver.common.by import By
from page_object_wework.page.base_page import BasePage
from page_object_wework.page.contact import ContactPage


class AddMemberPage(BasePage):
    __ele_username = (By.ID, 'username')
    __ele_accid = (By.ID, 'memberAdd_acctid')
    __ele_phone = (By.ID,'memberAdd_phone')

    def add_member(self,username,addid,phone):
        self.find(*self.__ele_username).send_keys(username)
        self.driver.find_element(*self.__ele_accid).send_keys(addid)
        self.driver.find_element(*self.__ele_phone).send_keys(phone)
        self.driver.find_element(By.CSS_SELECTOR,'.js_btn_save').click()
        return ContactPage(self.driver)

    def add_member_fail(self,username,addid,phone):
        self.driver.find_element(*self.__ele_username).send_keys(username)
        self.driver.find_element(*self.__ele_accid).send_keys(addid)
        self.driver.find_element(*self.__ele_phone).send_keys(phone)
        self.driver.find_element(By.CSS_SELECTOR, '.js_btn_save').click()
        element = self.driver.find_elements(By.CSS_SELECTOR,".ww_inputWithTips_tips")
        error_list =[]
        for ele in element:
            error_list.append(ele.text)
        return error_list

    def add_department(self,department):
        self.driver.find_element(By.CSS_SELECTOR, '.member_colLeft_top_addBtnWrap.js_create_dropdown').click()
        self.driver.find_element(By.CSS_SELECTOR, '.js_create_party').click()
        self.driver.find_element(By.NAME, 'name').send_keys(department)
        self.driver.find_element(By.CSS_SELECTOR, '.js_toggle_party_list').click()
        self.driver.find_element(By.CSS_SELECTOR, ".qui_dialog_body.ww_dialog_body [id='1688851087684739_anchor']").click()
        self.driver.find_element(By.XPATH, '//*[@id="__dialog__MNDialog__"]/div/div[3]/a[1]').click()
        element = self.driver.find_elements(By.CSS_SELECTOR,'.jstree.jstree-1.jstree-default')
        ele_list = []
        for ele in element:
            ele_list.append(ele.text)
        return ele_list